/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.cvut.fel.taskpro.view.controller;

import cz.cvut.fel.taskpro.business.imanager.ISubjectBusiness;
import cz.cvut.fel.taskpro.business.support.BusinessRuleException;
import cz.cvut.fel.taskpro.data.entity.Subject;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 * This controller is responsible for add subject to database. This controller is 
 * request scope and is called as subjectBean.
 * @author Tom
 * @version 1.0.0. beta
 */
@ManagedBean(name = "subjectBean")
@RequestScoped
public class SubjectBean extends AbstractController implements Serializable {
    @EJB
    private ISubjectBusiness subjectB;
    private Subject newSubject;
    
    @PostConstruct
    public void init(){
      recognizeLogin();
        newSubject=new Subject();
    }
    
    public SubjectBean(){    
    }
    
    /**
     * This function ask business layer for add new subject.
     * @see ISubjectBusiness#addSubject(cz.cvut.fel.taskpro.data.entity.Subject) 
     * 
     */
    
    public void createSubject(){
        try{ 
            subjectB.addSubject(newSubject);
            printSuccMessage("Creating subject:", "Subject was sucessfully created.");  
        }
        catch(BusinessRuleException ex){
            printErrMessage(ex.getExceptionCode(), ex.getErrorMessage());
        }
    }
        public Subject getNewSubject() {
        return newSubject;
    }

    public void setNewSubject(Subject newSubject) {
        this.newSubject = newSubject;
    }
    
}
